//
//  Extension+UIButton.swift
//  ZqlSinaWeiBo
//
//  Created by 赵乾龙 on 16/2/17.
//  Copyright © 2016年 Mr.zhao. All rights reserved.
//

import UIKit

extension UIButton {
    convenience init(backImageName:String?,imageName:String?){
        self.init()
        if backImageName != nil{
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
            setBackgroundImage(UIImage(named: backImageName! + "_highlighted"), forState: .Highlighted)
        }
        if imageName != nil{
        setImage(UIImage(named: imageName!), forState: .Normal)
            setImage(UIImage(named: imageName! + "_highlighted"), forState: .Highlighted)
        }
        //设置按钮和图片一样大
        sizeToFit()
    }
    
    
    convenience init(backImageName:String?,title:String,textColor:UIColor,imageName:String? = nil,fontSize:CGFloat = 14){
        self.init()
        
        if backImageName != nil{
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        }
        
        if imageName != nil{
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
        
        setTitle(title, forState: .Normal)
        setTitleColor(textColor, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        sizeToFit()
    }
    
    
}
